 @include "findsome.awk"
 @include "lib.awk"
 @include "nbins.awk"
 @include "dwrite.awk"

 function albrecht(  name,lo,hi,goals,d,w,has,at,row,active) {
   readbins(3,"albrecht",name,lo,hi,goals,d,w,has,at)
   #dwrite(d,name,w)
   keys(d,active)
   findsomeed1(d,at,name,w,active,"Queries=1,2 Inputs=1,2 Outputs=3 Files=3")
 }

 function china(  name,lo,hi,goals,d,w,has,at,row,active) {
   readbins(4,"china",name,lo,hi,goals,d,w,has,at)
   keys(d,active)
   findsomeed1(d,at,name,w,active,
               "AFP=2 Output=1,2,3,4 Added=1,2,3,4 Deleted=1,2,3,4  Resource=1,2,3,4 Duration=1,2,3,4")
 }

 function autompg(  name,lo,hi,goals,d,w,has,at,row,active) {
   readbins(10,"autompg25K",name,lo,hi,goals,d,w,has,at)
   keys(d,active)
   findsomeed1(d,at,name,w,active,
               "horsepower=1 weight=1 model=70 cylinders=4",1)
 }


 function _findsomeed(  name,lo,hi,goals,d,w,has,at,row,active) {
   readbins(3,"weathern",name,lo,hi,goals,d,w,has,at)
   dwrite(d,name,w)
   keys(d,active)
   findsomeed1(d,at,name,w,active,"windy=FALSE")
   findsomeed1(d,at,name,w,active,"windy=FALSE outlook=sunny")
   findsomeed1(d,at,name,w,active,"windy=FALSE outlook=sunny,rainy")
   findsomeed1(d,at,name,w,active,"windy=FALSE Temp1=3 outlook=sunny,rainy")
   findsomeed1(d,at,name,w,active,"windy=FALSE Humid=3 outlook=sunny,rainy")
 }

 function findsomeed1(d,at,name,w,active,str,silent,   query,rows,row,n) {
   query(str,name,query)
   n=findSome(query,rows,at,active)
   if (!silent) {     
     print "\n~~~~ | " str " |~~~~~~~~~~~~~~~~~~~~~~~~"
     print "#row,freq," hwrite(name,w)
     for(row=1;row<=n;row++)
       print rows[row]["id"] ", #" rows[row]["val"] "=, " rwrite(rows[row]["id"],d,w)}
   print length(rows) " records"
  }

# ~~~~ | windy=FALSE| = 8 |~~~~~~~~~~~~~~~~~~~~~~~~
# 4 #1 = (FALSE),(110),(rainy),(1),(3)
# 5 #1 = (FALSE),(90),(rainy),(1),(2)
# 8 #1 = (FALSE),(20),(sunny),(2),(3)
# 9 #1 = (FALSE),(114),(sunny),(1),(1)
# 10 #1 = (FALSE),(105),(rainy),(2),(2)
# 11 #1 = (FALSE),(101),(overcast),(3),(1)
# 1 #1 = (FALSE),(10),(sunny),(3),(2)
# 3 #1 = (FALSE),(100),(overcast),(3),(3)

# ~~~~ | windy=FALSE outlook=sunny| = 10 |~~~~~~~~~~~~~~~~~~~~~~~~
# 9 #2 = (FALSE),(114),(sunny),(1),(1)
# 1 #2 = (FALSE),(10),(sunny),(3),(2)
# 8 #2 = (FALSE),(20),(sunny),(2),(3)
# 10 #1 = (FALSE),(105),(rainy),(2),(2)
# 11 #1 = (FALSE),(101),(overcast),(3),(1)
# 12 #1 = (TRUE),(116),(sunny),(2),(1)
# 2 #1 = (TRUE),(12),(sunny),(3),(3)
# 3 #1 = (FALSE),(100),(overcast),(3),(3)
# 4 #1 = (FALSE),(110),(rainy),(1),(3)
# 5 #1 = (FALSE),(90),(rainy),(1),(2)

# ~~~~ | windy=FALSE outlook=sunny,rainy| = 12 |~~~~~~~~~~~~~~~~~~~~~~~~
# 8 #2 = (FALSE),(20),(sunny),(2),(3)
# 9 #2 = (FALSE),(114),(sunny),(1),(1)
# 10 #2 = (FALSE),(105),(rainy),(2),(2)
# 1 #2 = (FALSE),(10),(sunny),(3),(2)
# 4 #2 = (FALSE),(110),(rainy),(1),(3)
# 5 #2 = (FALSE),(90),(rainy),(1),(2)
# 11 #1 = (FALSE),(101),(overcast),(3),(1)
# 12 #1 = (TRUE),(116),(sunny),(2),(1)
# 14 #1 = (TRUE),(15),(rainy),(2),(3)
# 2 #1 = (TRUE),(12),(sunny),(3),(3)
# 3 #1 = (FALSE),(100),(overcast),(3),(3)
# 6 #1 = (TRUE),(15),(rainy),(1),(1)

# ~~~~ | windy=FALSE Temp1=3 outlook=sunny,rainy| = 12 |~~~~~~~~~~~~~~~~~~~~~~~~
# 1 #3 = (FALSE),(10),(sunny),(3),(2)
# 8 #2 = (FALSE),(20),(sunny),(2),(3)
# 9 #2 = (FALSE),(114),(sunny),(1),(1)
# 10 #2 = (FALSE),(105),(rainy),(2),(2)
# 11 #2 = (FALSE),(101),(overcast),(3),(1)
# 2 #2 = (TRUE),(12),(sunny),(3),(3)
# 3 #2 = (FALSE),(100),(overcast),(3),(3)
# 4 #2 = (FALSE),(110),(rainy),(1),(3)
# 5 #2 = (FALSE),(90),(rainy),(1),(2)
# 12 #1 = (TRUE),(116),(sunny),(2),(1)
# 14 #1 = (TRUE),(15),(rainy),(2),(3)
# 6 #1 = (TRUE),(15),(rainy),(1),(1)


